package controllers

import (
	"encoding/json"
	"fox/repositories"
	"github.com/gin-gonic/gin"
	"net/http"
)

type JsonRpcController struct {
	repository *repositories.UserRepository
}

func NewJsonRpcController() (userController *JsonRpcController) {
	var (
		userRepository *repositories.UserRepository
	)

	return &JsonRpcController{repository: userRepository}

}

func (controller *JsonRpcController) JsonRpcReturn(c *gin.Context) {

	var (
		jsonByte []byte
		jsonMap  map[string]interface{}
		err      error
	)
	jsonByte, _ = c.GetRawData()
	err = json.Unmarshal(jsonByte, &jsonMap)
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"message": "jsonMap绑定失败",
			"error":   err,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"message": "run",
		"data":    jsonMap,
	})
	return
}
